<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <script type="text/javascript" src="js/bootstrap.js"></script>
    <script type="text/javascript" src="js/ckform.js"></script>
    <script type="text/javascript" src="js/common.js"></script>
    <script src="js/jquery.min.js?v=2.1.4"></script>

    <style type="text/css">
        body {font-size: 20px;
            padding-bottom: 40px;
            background-color:#e9e7ef;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
	<%--提示消息插件--%>
    <script src="js/Dream-Msg/lib/dream-msg.min.js"></script>
    <script>
        let econtent = ""
        $(function () {
            //进入该页面，立即查询所有评论，做分页
            getEvaluates(1,"")
        })

        //根据查询条件查询评论
        function getEvaluateByEcontent() {
            econtent = $("#menuname").val()
            getEvaluates(1,econtent)
        }

        //删除评论
        function deleteComment(eid, pageNum) {
            <%--onclick="deleteComment(${evaluate.eid},${result.pageNum})"--%>
            // alert(eid+"---"+pageNum)
            if (confirm("你确定要删除该评论吗?")) {
                $.post("evaluate/deleteComment", "eid=" + eid, function (result) {
                    if (result.status == 1) {
                        //删除成功
                        Dreamer.success(result.message);
                        //删除数据是最后一页的最后一条数据时，做个标记，当删除成功时，返回前一页
                        if ($("#flag").val() == "true") {
                            //刷新
                            getEvaluates((pageNum - 1),'${econtent}')
                        } else {
                            //刷新
                            getEvaluates(pageNum,'${econtent}')
                        }
                    } else {
                        Dreamer.error(result.message);
                    }
                });
            }
        }



        function getEvaluates(pageNo,econtent) {
            $.post("evaluate/getEvaluate",{"pageNo":pageNo,"econtent":econtent},function (result) {
                //删除数据是最后一页的最后一条数据时，做个标记，当删除成功时，返回前一页
                if (result.total % result.pageSize == 1 && result.pageNum == result.pages) {
                    $("#flag").val(true)
                } else {
                    $("#flag").val(false)
                }

                // alert(JSON.stringify(result))
                let evaluatelist = '';
                result.list.forEach(function (evaluate) {
                    evaluatelist += `
                        <tr>
                                <td>\${evaluate.econtent}</td>
                                <td><a href="user_detail.jsp?uid=\${evaluate.user.uid}">\${evaluate.user.truename}</a></td>
                                <td>\${evaluate.blog.btitle}</td>
                                <td>\${evaluate.etime}</td>
                                <td><button type="button"  eid="\${evaluate.eid}" class="deletecomment"
                                    onclick="deleteComment(\${evaluate.eid},\${result.pageNum})">删除</button></td>

                        </tr>
                    `;
                });
                $("#tbody").html(evaluatelist);
                //处理分页
                let start = '';
                if (result.pageNum <= 1) {
                    start += `<a href="javascript:void(0)"><span style="color: #3a3c3c">首页</span></a>&nbsp;
                                <a href="javascript:void(0)"><span style="color: #3a3c3c">上一页</span></a>`;
                } else {
                    start += `<a href="javascript:getEvaluates(1,'\${econtent}')">首页</a>&nbsp;
                                <a href="javascript:getEvaluates(\${result.pageNum-1},'\${econtent}')">上一页</a>`;
                }
                let end = '';
                if (result.pageNum >= result.pages) {
                    end += `<a href="javascript:void(0)"><span style="color: #3a3c3c">下一页</span></a>&nbsp;
                                <a href="javascript:void(0)"><span style="color: #3a3c3c">末页</span></a>`;
                } else {
                    end += `<a href="javascript:getEvaluates(\${result.pageNum+1},'\${econtent}')">下一页</a>&nbsp;
                                <a href="javascript:getEvaluates(\${result.pages},'\${econtent}')">末页</a>`;
                }

                let nums = '';
                result.navigatepageNums.forEach(function (num) {
                    if (num == result.pageNum) {
                        nums += `<a href="javascript:void(0)" style="color: red">\${num}</a>&nbsp;&nbsp;&nbsp;`;
                    } else {
                        nums += `<a href="javascript:getEvaluates(\${num},'\${econtent}')">\${num}</a>&nbsp;&nbsp;&nbsp;`;
                    }
                })

                let foot = `\${start}  【&nbsp;&nbsp;\${nums}】  \${end}   |||   总数据量:\${result.total}`;
                $("#pagenationId").html(foot)
            })
        }
    </script>
</head>
<body>
<input type="hidden" name="flag" id="flag">
<input type="hidden" name="econtent" id="econtent">
<form class="form-inline definewidth m20" action="#" method="get">
     <font color="#777777"><strong>查询评价：</strong></font>
    <input type="text" name="menuname" id="menuname"class="abc input-default" placeholder="" value="">&nbsp;&nbsp; 
    <button type="button" class="btn btn-primary queryBtn" onclick="getEvaluateByEcontent()">查询评价</button>&nbsp;&nbsp;
	
</form>
<table class="table table-bordered table-hover definewidth m10">
    <thead>
    <tr>
        <th>评价内容</th>
        <th>评价人</th>
        <th>博客标题</th>
        <th>评价时间</th>
        <th>操作</th>
    </tr>
    </thead>
	    <tbody id="tbody">
        <tr>
                
                <td>你来人间一趟，你要看看太阳，和你的心上人，一起走在街上。</td>
				<td><a href="user_detail.jsp">小强</a></td>
                <td>你好,李焕英观后感</td>
                <td>2016.02.12</td>
                <td><button type="button"  id="deletecomment">删除</button></td>
               
        </tr>
        </tbody>
            <tfoot id="tfoot">
            <%--设置分页信息--%>
            <tr>
                <td colspan="5" id="pagenationId">

                </td>
            </tr>
            </tfoot>
       
       </table>

</body>
</html>
